
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>cAdvisor InfluxDB Grafana搭建监控平台 · docker swarm实践文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Carey">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-emphasize/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="telegraf.html" />
    
    
    <link rel="prev" href="portainer.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://carey.akhack.com" target="_blank" class="custom-link">Home</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    基础环境
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../base_book/环境介绍.html">
            
                <a href="../base_book/环境介绍.html">
            
                    
                    环境介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../base_book/环境准备.html">
            
                <a href="../base_book/环境准备.html">
            
                    
                    基础准备
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../base_book/安装docker.html">
            
                <a href="../base_book/安装docker.html">
            
                    
                    安装 docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../base_book/compose_file.html">
            
                <a href="../base_book/compose_file.html">
            
                    
                    compose file文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../base_book/registry仓库管理.html">
            
                <a href="../base_book/registry仓库管理.html">
            
                    
                    registry管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    swarm 群集
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="创建群集.html">
            
                <a href="创建群集.html">
            
                    
                    创建群集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="portainer.html">
            
                <a href="portainer.html">
            
                    
                    swarm管理工具Portainer
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.3" data-path="群集监控.html">
            
                <a href="群集监控.html">
            
                    
                    cAdvisor InfluxDB Grafana搭建监控平台
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="telegraf.html">
            
                <a href="telegraf.html">
            
                    
                    Telegraf监控容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="Chronograf.html">
            
                <a href="Chronograf.html">
            
                    
                    Chronograf显示监控数据
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    swarm service
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../service_book/nginx.html">
            
                <a href="../service_book/nginx.html">
            
                    
                    部署nginx服务
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    swarm stack
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../swarm_stack/lnmpwordpress.html">
            
                <a href="../swarm_stack/lnmpwordpress.html">
            
                    
                    部署wordpress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../swarm_stack/build_eureka.md">
            
                <span>
            
                    
                    部署eureka
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >cAdvisor InfluxDB Grafana搭建监控平台</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="cadvisor-influxdb-grafana&#x642D;&#x5EFA;&#x76D1;&#x63A7;&#x5E73;&#x53F0;">cAdvisor InfluxDB Grafana&#x642D;&#x5EFA;&#x76D1;&#x63A7;&#x5E73;&#x53F0;</h1>
<h2 id="&#x521B;&#x5EFA;&#x76D1;&#x63A7;&#x4F7F;&#x7528;&#x7F51;&#x7EDC;">&#x521B;&#x5EFA;&#x76D1;&#x63A7;&#x4F7F;&#x7528;&#x7F51;&#x7EDC;</h2>
<p>&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x8DE8;&#x4E3B;&#x673A;&#x76D1;&#x63A7;&#x6570;&#x636E;&#x4EA4;&#x6362;&#xFF0C;&#x4E3A;&#x76D1;&#x63A7;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;<code>overlay</code>&#x7F51;&#x7EDC;</p>
<pre><code>docker network create --driver overlay monitor
</code></pre><h2 id="influxdb">InfluxDB</h2>
<p><a href="https://docs.influxdata.com/influxdb/v1.5/" target="_blank">InfluxDB</a> &#x662F;&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x5206;&#x5E03;&#x5F0F;&#x65F6;&#x5E8F;&#x3001;&#x4E8B;&#x4EF6;&#x548C;&#x6307;&#x6807;&#x6570;&#x636E;&#x5E93;,&#x7528;&#x4E8E;&#x5904;&#x7406;&#x9AD8;&#x5199;&#x5165;&#x548C;&#x67E5;&#x8BE2;&#x8D1F;&#x8F7D;&#x3002;</p>
<p><strong>&#x5B89;&#x88C5;<a href="https://hub.docker.com/_/influxdb/" target="_blank">InfluxDB</a>,&#x7528;&#x4E8E;&#x6536;&#x96C6;&#x5BB9;&#x5668;&#x76D1;&#x63A7;&#x6570;&#x636E;</strong></p>
<pre><code>docker service create --network monitor -p 8083:8083 -p 8086:8086 --mount source=influxdb-vol,type=volume,target=/var/lib/influxdb --name=influxdb --constraint &apos;node.hostname==node1&apos; influxdb
</code></pre><ul>
<li><code>8086</code>&#x7528;&#x4E8E;Influxdb&#x6570;&#x636E;&#x8BFB;&#x5199;,<code>8083</code>&#x7528;&#x4E8E;&#x6570;&#x636E;&#x5E93;&#x7BA1;&#x7406;&#x754C;&#x9762;</li>
<li><code>--constraint &apos;node.hostname==node1&apos;</code> &#x7528;&#x4E8E;&#x7EA6;&#x675F;influxdb&#x8FD0;&#x884C;&#x5728;node1&#x4E0A;</li>
<li><code>--mount</code> &#x6302;&#x8F7D;&#x4E00;&#x4E2A;volume&#x5230;&#x5BB9;&#x5668;&#x7684;<code>/var/lib/influxdb</code>&#x7528;&#x4E8E;&#x6570;&#x636E;&#x6301;&#x4E45;&#x5316;</li>
</ul>
<p>&#x767B;&#x5F55;Influxdb&#x7BA1;&#x7406;&#x63A7;&#x5236;&#x53F0;&#xFF0C;&#x70B9;&#x51FB;&#x8BBE;&#x7F6E;-&gt;&#x8F93;&#x5165;&#x7528;&#x6237;&#x540D;&#x5BC6;&#x7801;<span class="pg-emphasize pg-emphasize-yellow" style="">(&#x9ED8;&#x8BA4;&#x7528;&#x6237;&#x540D;:<code>root</code>, &#x5BC6;&#x7801;:<code>root</code>)</span>
&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7528;&#x4E8E;cadvisor&#x5B58;&#x50A8;&#x76D1;&#x63A7;&#x6570;&#x636E;&#x7684;&#x6570;&#x636E;&#x5E93;</p>
<pre><code>CREATE DATABASE &quot;cadvisor&quot;
</code></pre><h2 id="cadvisor">cAdvisor</h2>
<p><a href="https://hub.docker.com/r/google/cadvisor/" target="_blank">cAdviosr</a>&#x662F;Google&#x7528;&#x6765;&#x76D1;&#x6D4B;&#x5355;&#x8282;&#x70B9;&#x7684;&#x8D44;&#x6E90;&#x4FE1;&#x606F;&#x7684;&#x76D1;&#x63A7;&#x5DE5;&#x5177;</p>
<p><strong>&#x5B89;&#x88C5;cadvisor, &#x9700;&#x8981;&#x5728;&#x6240;&#x6709;&#x8282;&#x70B9;&#x5B89;&#x88C5;&#xFF0C;&#x7528;&#x4E8E;&#x6536;&#x96C6;&#x4E2A;&#x8282;&#x70B9;&#x5BB9;&#x5668;&#x8D44;&#x6E90;&#x4FE1;&#x606F;</strong></p>
<pre><code>docker service create --network monitor --name cadvisor -p 8080:8080 --mode global --mount source=/var/run,type=bind,target=/var/run,readonly=false --mount source=/,type=bind,target=/rootfs,readonly=true --mount source=/sys,type=bind,target=/sys,readonly=true --mount source=/var/lib/docker,type=bind,target=/var/lib/docker,readonly=true google/cadvisor -storage_driver=influxdb -storage_driver_host=influxdb:8086 -storage_driver_db=cadvisor
</code></pre><ul>
<li><code>--mode global</code>&#x7528;&#x4E8E;&#x5728;&#x5404;&#x4E2A;&#x8282;&#x70B9;&#x5404;&#x90E8;&#x7F72;&#x4E00;&#x4E2A;&#x526F;&#x672C;</li>
<li><code>--mount</code> &#x6302;&#x8F7D;&#x672C;&#x5730;socket&#x7528;&#x4E8E;&#x6536;&#x96C6;&#x8D44;&#x6E90;&#x4FE1;&#x606F;</li>
<li><code>-storage_driver=influxdb</code> &#x6307;&#x5B9A;&#x5B58;&#x50A8;&#x8BBE;&#x5907;</li>
<li><code>-storage_driver_host=influxdb:8086</code> &#x6307;&#x5B9A;influxdb&#x5730;&#x5740;</li>
<li><code>-storage_driver_db=cadvisor</code> &#x6307;&#x5B9A;&#x5B58;&#x50A8;&#x6570;&#x636E;&#x5E93;</li>
<li><code>-storage_driver_user=root</code> &#x6307;&#x5B9A;&#x6570;&#x636E;&#x5E93;&#x7528;&#x6237;&#x540D; (&#x9ED8;&#x8BA4;root&#xFF0C;&#x53EF;&#x4E0D;&#x5199;)</li>
<li><code>-storage_driver_password=root</code> &#x6307;&#x5B9A;&#x6570;&#x636E;&#x5E93;&#x5BC6;&#x7801; (&#x9ED8;&#x8BA4;root&#xFF0C;&#x53EF;&#x4E0D;&#x5199;)</li>
</ul>
<p><code>cAdvisor</code>&#x8FD0;&#x884C;&#x4EE5;&#x540E;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>http://10.0.20.121:8080/</code>&#x67E5;&#x770B;&#x5230;Docker&#x8FD0;&#x884C;&#x7684;&#x673A;&#x5668;&#x548C;&#x5BB9;&#x5668;&#x60C5;&#x51B5;&#x3002;</p>
<h2 id="grafana">Grafana</h2>
<p><a href="https://hub.docker.com/r/grafana/grafana/" target="_blank">Graphite</a> &#x662F;&#x4E00;&#x6B3E;&#x5F00;&#x6E90;&#x7684;&#x76D1;&#x63A7;&#x7ED8;&#x56FE;&#x5DE5;&#x5177;&#x3002;&#x53EF;&#x4EE5;&#x5B9E;&#x65F6;&#x6536;&#x96C6;&#x3001;&#x5B58;&#x50A8;&#x3001;&#x663E;&#x793A;&#x65F6;&#x95F4;&#x5E8F;&#x5217;&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x3002;</p>
<p><strong>&#x5B89;&#x88C5;grafana</strong></p>
<pre><code>docker service create --network monitor -p 3000:3000 --name grafana --constraint &apos;node.hostname==node1&apos; --mount source=grafana-vol,type=volume,target=/var/lib/grafana grafana/grafana
</code></pre><p><strong>&#x767B;&#x5F55;&#x5230;Grfana</strong></p>
<p>&#x6D4F;&#x89C8;&#x5668;&#x6253;&#x5F00;<code>http://10.0.20.121:3000</code> <span class="pg-emphasize pg-emphasize-yellow" style="">(&#x9ED8;&#x8BA4;&#x7528;&#x6237;&#x540D;<code>admin</code>,&#x5BC6;&#x7801;<code>admin</code>)</span></p>
<p><strong>&#x914D;&#x7F6E;&#x6570;&#x636E;&#x6E90;</strong></p>
<p>&#x56E0;&#x4E3A;&#x4F7F;&#x7528;overlay&#x7F51;&#x7EDC;&#xFF0C;URL&#x586B;&#x5199;<code>http://influxdb:8086</code>&#x5373;&#x53EF;
<img src="http://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/grafana_data_source.png" alt=""></p>
<p><strong>&#x521B;&#x5EFA;Dashboard</strong></p>
<blockquote>
<p><strong>[warning] &#x8FD9;&#x91CC;&#x6709;&#x4E2A;&#x5C0F;&#x95EE;&#x9898;,&#x521B;&#x5EFA;&#x7684;&#x56FE;&#x6807;&#x4F1A;&#x6709;&#x5DE6;&#x4E0A;&#x89D2;&#x6709;&#x4E2A;&#x7EA2;&#x8272;<code>!</code>&#xFF0C;&#x5E76;&#x4E14;&#x521B;&#x5EFA;&#x7684;&#x56FE;&#x65E0;&#x6CD5;&#x4F7F;&#x7528;,&#x63D0;&#x793A;&#x5982;&#x4E0B;&#xFF1A;</strong></p>
</blockquote>
<pre><code>Invalid interval string, expecting a number followed by one of &quot;Mwdhmsy&quot;
</code></pre><p>&#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#x53C2;&#x8003;&#x5B98;&#x65B9;github <strong><a href="https://github.com/grafana/grafana/issues/8510" target="_blank">issues</a></strong>&#x3002; &#x6211;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x7248;&#x672C;&#x76EE;&#x524D;&#x4E3A;&#x6700;&#x65B0;&#xFF0C;&#x89E3;&#x51B3;&#x539F;&#x7406;&#x4E00;&#x6837;&#x53EA;&#x662F;&#x4FEE;&#x6539;&#x5730;&#x65B9;&#x6709;&#x70B9;&#x533A;&#x522B;
<img src="http://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/grafana_error.png" alt=""></p>
<p>&#x5B98;&#x65B9;&#x5BF9;&#x8BE5;&#x9009;&#x9879;&#x89E3;&#x91CA;&#x5982;&#x4E0B;</p>
<pre><code>A lower limit for the auto group by time interval. Recommended to be set to write frequency, for example 1m if your data is written every minute. Access auto interval via variable $__interval for time range string and $__interval_ms for numeric variable that can be used in math expressions
</code></pre><blockquote>
<p><strong>[info] &#x5927;&#x81F4;&#x610F;&#x601D;&#x4E3A;&#xFF1A;&#x6309;&#x7167;&#x65F6;&#x95F4;&#x8FDB;&#x884C;&#x81EA;&#x52A8;&#x5206;&#x7EC4;&#xFF0C;&#x5EFA;&#x8BAE;&#x8BBE;&#x7F6E;&#x4E3A;&#x6570;&#x636E;&#x5199;&#x5165;&#x7684;&#x9891;&#x7387;&#x3002;</strong></p>
</blockquote>
<p><strong>&#x4F8B;&#x5B50;&#xFF1A;</strong></p>
<p>cpu&#x76D1;&#x63A7;&#x56FE;&#x8868;sql</p>
<pre><code>SELECT mean(&quot;value&quot;) FROM &quot;cpu_usage_system&quot; WHERE (&quot;com.docker.swarm.service.name&quot; = &apos;cadvisor&apos;) AND $timeFilter GROUP BY time($__interval) fill(null)
SELECT mean(&quot;value&quot;) FROM &quot;cpu_usage_system&quot; WHERE (&quot;com.docker.swarm.service.name&quot; = &apos;grafana&apos;) AND $timeFilter GROUP BY time($__interval) fill(null)
SELECT mean(&quot;value&quot;) FROM &quot;cpu_usage_system&quot; WHERE (&quot;com.docker.swarm.service.name&quot; = &apos;influxdb&apos;) AND $timeFilter GROUP BY time($__interval) fill(null)
</code></pre><p><img src="http://carey-akhack-com.oss-cn-hangzhou.aliyuncs.com/book/swarm/grafana_dashboard.png" alt=""></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="portainer.html" class="navigation navigation-prev " aria-label="Previous page: swarm管理工具Portainer">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="telegraf.html" class="navigation navigation-next " aria-label="Next page: Telegraf监控容器">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"cAdvisor InfluxDB Grafana搭建监控平台","level":"1.3.3","depth":2,"next":{"title":"Telegraf监控容器","level":"1.3.4","depth":2,"path":"swarm_book/telegraf.md","ref":"swarm_book/telegraf.md","articles":[]},"previous":{"title":"swarm管理工具Portainer","level":"1.3.2","depth":2,"path":"swarm_book/portainer.md","ref":"swarm_book/portainer.md","articles":[]},"dir":"ltr"},"config":{"plugins":["emphasize","alerts","code","-lunr","-search","search-plus","splitter"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"emphasize":{},"splitter":{},"code":{"copyButtons":true},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"alerts":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{}},"theme":"default","author":"Carey","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"docker swarm实践文档","language":"zh-hans","links":{"sidebar":{"Home":"http://carey.akhack.com"}},"gitbook":"*"},"file":{"path":"swarm_book/群集监控.md","mtime":"2018-07-06T03:01:13.282Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-12-04T03:25:36.834Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

